<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div style="padding: 10px;">
	<form class="op-form" id="addForm" name="addForm" method="post">
		<input type="hidden" id="uniqueCodeResult">
		<table>
			<tr>
				<td>姓名:</td>
				<td>
					<input class="easyui-validatebox" name="name" required="true" validType="chinese;length[2,12]">
				</td>
			</tr>
			<tr>
				<td>性别:</td>
				<td>
					<select id="sex" name="sex" class="easyui-combobox" required="true" style="width: 206px;">
						<option value="" selected="selected"></option>
						<option value="0">女</option>
						<option value="1">男</option>
					</select>
				</td>
			</tr>
			<tr>
				<td>账户:</td>
				<td>
					<input class="easyui-validatebox" name="code" required="true" validType="length[2,20];uniqueUserCode">
				</td>
			</tr>
			<tr>
				<td>初始密码:</td>
				<td>
					<input type="password" class="easyui-validatebox" name="psw" required="true" validType="length[2,20]">
				</td>
			</tr>
			<tr>
				<td>确认密码:</td>
				<td>
					<input type="password" class="easyui-validatebox" name="rpsw" required="true" validType="length[2,20];reinput[$('input[name=psw]').val(),$('input[name=rpsw]').val()]">
				</td>
			</tr>
			<tr>
				<td>联系电话:</td>
				<td>
					<input class="easyui-validatebox" name="phone" required="false" validType="telephone">
				</td>
			</tr>
			<tr>
				<td>家庭住址:</td>
				<td>
					<input class="easyui-validatebox" name="address" required="false" validType="length[2,100]">
				</td>
			</tr>
			<tr>
				<td>手机:</td>
				<td>
					<input class="easyui-validatebox" name="mobile" required="true" validType="mobile">
				</td>
			</tr>
			<tr>
				<td>Email:</td>
				<td>
					<input class="easyui-validatebox" name="email" required="false" validType="email">
				</td>
			</tr>
			<tr>
				<td>角色:</td>
				<td>
					<select id="roleid" name="roleid" class="easyui-combobox" required="true" style="width: 206px;"></select>
				</td>
			</tr>
			<tr>
				<td>个人说明:</td>
				<td>
					<textarea class="easyui-validatebox" name="others" required="false" validType="length[0,100]" style="height:100px;"></textarea>
				</td>
			</tr>
			<tr>
				<td>
					<a id="btnSubmit" href="#" class="easyui-linkbutton" icon="icon-ok" onclick="$('#addForm').submit();">提交</a>
				</td>
				<td>
					<a href="#" class="easyui-linkbutton" icon="icon-cancel" onclick="addForm.reset()">重置</a>
					<a href="#" class="easyui-linkbutton" icon="icon-redo" onclick="addForm.reset();$('#dataGrid').show();$('#opPanel').panel('close');">返回</a>
				</td>
			</tr>
		</table>
	</form>
</div>

<script type="text/javascript">
	
	$(document).ready(function(){
		
		$('#roleid').combobox({
		    url: 'user.action?command=getRoles',
		    valueField: 'id',
		    textField: 'name'
		});
		
		$('#addForm').form({
			onSubmit: function(){
				if($(this).form('validate')){
					$("#btnSubmit").linkbutton({disabled:true});
					ajaxAdd();
				}else{
					return false;
				}
			}
		});
	});
	
	function ajaxAdd(){
		var actionURL = "user.action?command=add";
		var params = $("#addForm").serialize();
		
		jQuery.ajax({
			url: actionURL,
			type: "post",
			cache: false,
			data: params,
			success: function(result){
				if("true" == result){
					$.messager.alert("友情提示", "您的操作成功!", "info", function(){
						$('#tt').datagrid('reload');
						$("#dataGrid").show();
						$("#opPanel").panel("close");
					});
				}else{
					$.messager.alert("友情提示", "您的操作失败!", "error");
				}
			}
		});
	}
</script>